package com.example.prison.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.prison.entity.SecurityDeviceInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author jiang
* @description 针对表【security_device_info】的数据库操作Mapper
* @createDate 2023-04-19 11:31:11
* @Entity com.example.military.entity.SecurityDeviceInfo
*/
@Mapper
public interface SecurityDeviceInfoMapper extends BaseMapper<SecurityDeviceInfo> {

//    @Select("select * from security_device_info order by device_id desc")
    @Select("<script>select * from security_device_info " +
            " <where> " +
            " <if test=\"deviceName != null and deviceName != ''\">and device_name like concat('%',#{deviceName},'%') </if> " +
            " <if test=\"deviceNumber != null and deviceNumber != ''\">and device_number like concat('%',#{deviceNumber},'%') </if> " +
            " </where> " +
            "order by device_id desc</script>")
    List<SecurityDeviceInfo> get(@Param("deviceName")String deviceName, @Param("deviceNumber")String deviceNumber);

    @Insert("insert into security_device_info(device_name, device_number, device_area, is_use, device_status) values (#{deviceName}, #{deviceNumber}, #{deviceArea}, #{isUse}, #{deviceStatus})")
    int add(SecurityDeviceInfo seDevice);

    @Delete("<script>delete from security_device_info where device_id in <foreach collection=\"ids\" item=\"item\" open=\"(\" separator=\",\" close=\")\">#{item} </foreach> </script>")
    void deleteSecurityDevice(@Param("ids") Integer[] ids);

    @Delete("delete from security_device_info where device_number=#{deviceNumber}")
    void deleteByNumber(@Param("deviceNumber") String deviceNumber);

//    @Update("update security_device_info set device_name=#{seDevice.deviceName},device_number=#{seDevice.deviceNumber}," +
//            "device_area=#{seDevice.deviceArea},is_use=#{seDevice.isUse},device_status=#{seDevice.deviceStatus} where device_id = #{deviceId}")
    @Update({"<script> UPDATE security_device_info",
            "<set>",
            "<if test='seDevice.deviceName != null'>device_name = #{seDevice.deviceName},</if>",
            "<if test='seDevice.deviceNumber != null'>device_number = #{seDevice.deviceNumber},</if>",
            "<if test='seDevice.deviceArea != null'>device_area = #{seDevice.deviceArea},</if>",
            "<if test='seDevice.isUse != null'>is_use = #{seDevice.isUse},</if>",
            "<if test='seDevice.deviceStatus != null'>device_status = #{seDevice.deviceStatus},</if>",
            "</set>",
            "where device_id = #{deviceId} </script>"})
    int updateSecurityDevice(SecurityDeviceInfo seDevice,Integer deviceId);

    @Select("select * from security_device_info where device_id=#{deviceId}")
    SecurityDeviceInfo getById(@Param("deviceId") Integer deviceId);

    @Select("select * from security_device_info where device_name like concat('%',#{deviceName},'%') order by device_id desc")
    List<SecurityDeviceInfo> getByName(@Param("deviceName") String deviceName);

    @Select("select * from security_device_info where device_number like concat('%',#{deviceNumber},'%') order by device_id desc")
    List<SecurityDeviceInfo> getByNumber(@Param("deviceNumber") String deviceNumber);

    @Select("select * from security_device_info where device_number=#{deviceNumber}")
    SecurityDeviceInfo getOneByNumber(@Param("deviceNumber") String deviceNumber);

}




